import request from "@/utils/request";

// 登录方法
export function login(username, password, code, uuid) {
  const data = {
    username,
    password
  };
  return request({
    url: "/auth/login",
    method: "post",
    data: data
  });
}

// 刷新方法
export function refreshToken(token) {
  console.log("refreshToken", token);
  return request({
    url: "/auth/refreshToken",
    method: "get",
    params: { token: token }
  });
}

// 获取用户详细信息
export function getInfo() {
  return request({
    url: "/auth/accountInfo",
    method: "get"
  });
}

// 退出方法
export function logout(href) {
  return request({
    url: "/auth/ssologout",
    method: "post",
    params: { redirectUrl: href }
  });
}

// 获取验证码
export function getCodeImg() {
  return request({
    url: "/captchaImage",
    method: "get"
  });
}

// 获取菜单权限树
export function getPermissionTrees() {
  return request({
    url: "/plat/permission/tree",
    method: "get"
  });
}

//获取重定向地址
export const getAuthorizeUrl = targetUrl => {
  return request({
    url: "/auth/getAuthorizeUrl",
    method: "get",
    params: { targetUrl }
  });
};

//sso登陆
export const ssologin = code => {
  return request({
    url: "/auth/ssologin",
    method: "post",
    params: { code }
  });
};
